package ServletDemo2;//package ServletDemo01;
import entity.Books;

import util.GokJDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Servlet implementation class deleteServlet
 */
@WebServlet("/BooksDelete")
public class BooksDelete extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public BooksDelete() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String bookId = request.getParameter("bookId");
        int result = GokJDBCUtil.update("DELETE FROM books WHERE bookId=?", bookId);
        response.setContentType("text/plain;charset=UTF-8");
        if (result > 0) {
            response.sendRedirect("home.jsp"); // 删除成功，重定向到主页
        } else {
            response.getWriter().write("failure"); // 删除失败
        }
    }




    /**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
